package com.baizhi.controller;


import com.baizhi.entity.User;
import com.baizhi.service.IUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author haiyu
 * @since 2021-08-26
 */
@RestController
@RequestMapping("/user")
public class UserController {

        @Autowired
        private IUserService us;
    @GetMapping("/login/{name}/{pwd}")
    public User login(@PathVariable("name") String name, @PathVariable("pwd")Integer pwd
    , HttpSession session){
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username",name).eq("password",pwd);
       // return  us.getOne(wrapper);//此处要变换
        User user = us.getOne(wrapper);
        if(user!=null){
            session.setAttribute("user",user);
        }
        return  user;//用于登录成功后显示用户名
    }
    @PostMapping("/zx")
    public void login(HttpSession session){
        session.invalidate();//销毁session
    }
}

